Load your data and plot the figures. The following code reads the
data and plots the figures. The cs object is the result of
the cytosignal analysis, and the colors.list
object is the color list for the ligands and receptors. The
plot.path variable specifies the output directory for the
figures.
library(cytosignal)
source("path_to_plotting_functions.R")
cs <- readRDS("path/to/cs-obj_slide-tag_E14.5_cortex.rds")
colors.list <- readRDS("path/to/st.color.list.rds")
Specify the ligand-receptor interaction to plot. The
use.intr variable specifies the ligand-receptor interaction
to plot. Now plot the first example of WNT5A-EPHA7
interaction, which is a diffusino-dependent interaction.
signif.use <- "result.hq"
lrscore.slot <- "diffusion-Raw_smooth"
intr.names <- cytosignal:::getIntrNames(cs, showIntr(cs, lrscore.slot, signif.use))
use.intr = "WNT5A-EPHA7"
use.CPI = names(intr.names[which(intr.names == use.intr)])
plot.rank = which(intr.names == use.intr)
plotSignif2(cs, intr = plot.rank, edge = T, pt.size = 0.5, raster = F, resolution = 200,
colors.list = colors.list, slot.use = lrscore.slot, signif.use = signif.use,
return.plot = T)
## $`WNT5A-EPHA7`
Now plot the second example of EFNB1-EPHA4
interaction.
signif.use <- "result.hq"
lrscore.slot <- "contact-Raw_smooth"
intr.names <- cytosignal:::getIntrNames(cs, showIntr(cs, lrscore.slot, signif.use))
use.intr = "EFNB1-EPHA4"
use.CPI = names(intr.names[which(intr.names == use.intr)])
plot.rank = which(intr.names == use.intr)
plotSignif2(cs, intr = plot.rank, edge = T, pt.size = 0.5, raster = F, resolution = 200,
colors.list = colors.list, slot.use = lrscore.slot, signif.use = signif.use,
return.plot = T)
## $`EFNB1-EPHA4`
diff.res.hq = cs@lrscore[["diffusion-Raw_smooth"]]@res.list[["result.spx"]]
cont.res.hq = cs@lrscore[["contact-Raw_smooth"]]@res.list[["result.spx"]]
locs = as.data.frame(cs@cells.loc)
diff.df = count_cell_features(diff.res.hq, rownames(locs))
cont.df = count_cell_features(cont.res.hq, rownames(locs))
all.df = cbind(diff.df, cont.df)
all.df[,3] = all.df[,1] + all.df[,2]
colnames(all.df) = c("diff", "cont", "total")
plot.df = cbind(locs, all.df[rownames(locs), ])
p1 = plotSigPerCell(plot.df, plot.class = "diff", pt.size = 0.9)
p2 = plotSigPerCell(plot.df, plot.class = "cont", pt.size = 0.9)
cowplot::plot_grid(p1, p2, nrow = 1)
slot.use = "contact-Raw_smooth"
signif.use = "result.hq"
use.intr = "EFNB1-EPHA4"
intr.names = cytosignal:::getIntrNames(cs, showIntr(cs, slot.use, signif.use))
use.CPI = names(intr.names[which(intr.names == use.intr)])
plot.df = as.data.frame(cs@cells.loc)
plot.df$cluster = cs@clusters[rownames(plot.df)]
rm.cells = which(plot.df[, 1] < -900)
plot.df = plot.df[-rm.cells, ]
# compute the distance between each cell to the center cell
center.cell = c(mean(cs@cells.loc[, "x"]), mean(cs@cells.loc[, "y"]))
center.cell.dist = sapply(rownames(plot.df), function(x) {
sqrt((plot.df[x, "x"] - center.cell[1])^2 + (plot.df[x, "y"] - center.cell[2])^2)
})
dist.plot.df = as.data.frame(cs@cells.loc[rownames(plot.df),])
dist.plot.df$dist = center.cell.dist[rownames(dist.plot.df)]
dist.plot.df$score = cs@lrscore[["contact-Raw_smooth"]]@score[rownames(dist.plot.df), use.CPI]
dist.plot.df$cluster = cs@clusters[rownames(dist.plot.df)]
dist.lo = loess(score ~ dist, data = dist.plot.df, family = "gaussian", span = 0.3)
dist.lo.pred = predict(dist.lo, dist.plot.df$dist)
# plot the results using ggplot2
p1 = ggplot(dist.plot.df, aes(x = dist, y = score, color = cluster)) + geom_point(size = 1, stroke = 0.2) +
scale_color_manual(values = colors.list)+
geom_line(aes(x = dist, y = dist.lo.pred), color = "red", size = 1) +
cowplot::theme_cowplot(12)+
ylim(0, 3)+
labs(x = "Distance to the L5/6 layer", y = "LRscore")+
theme(panel.background = element_blank(),
panel.border = element_blank(),
# axis.line = element_blank(),
# axis.text = element_blank(),
# axis.ticks = element_blank(),
axis.title = element_blank(),
legend.position = "none")
print(p1)
Plot the circos plot for the all diffusion-dependent interactions.
abbrev = toupper(abbreviate(levels(cs@clusters), minlength = 3))
abbrev[4] = "N_1"
slot.use = "diffusion-Raw_smooth"
edge.df = getNormEdgeDF(cs, db.use = slot.use)
edge.mtx = DFtoMtx(edge.df)
clust.col = colors.list[c(rownames(edge.mtx), colnames(edge.mtx))]
# abbreviate the row and column names to two letters
edge.mtx.1 = edge.mtx
rownames(edge.mtx.1) = unname(abbrev[rownames(edge.mtx.1)])
colnames(edge.mtx.1) = unname(abbrev[colnames(edge.mtx.1)])
rownames(edge.mtx.1) = paste0("s-", rownames(edge.mtx.1))
colnames(edge.mtx.1) = paste0("r-", colnames(edge.mtx.1))
names(clust.col) = c(rownames(edge.mtx.1), colnames(edge.mtx.1))
# set the order based on the rowSums and colSums
col.order = colnames(edge.mtx.1)[order(colSums(edge.mtx.1), decreasing = T)]
row.order = rownames(edge.mtx.1)[order(rowSums(edge.mtx.1), decreasing = F)]
# chordDiagram takes union(rownames, colnames) as the order
use.order = c(row.order, col.order)
# plotting circos
circos.clear()
circos.par("track.height"=0.8, cell.padding=c(0, 0, 0, 0))
par(cex = 1, mar = c(0, 0, 0, 0))
chordDiagram(
edge.mtx.1, big.gap = 15, grid.col = clust.col, annotationTrack = "grid", order = use.order,
annotationTrackHeight = c(0.03, 0.01),
preAllocateTracks = list(
track.height = max(strwidth(unlist(dimnames(edge.mtx.1))))/2
)
)
circos.track(
track.index = 1, panel.fun = function(x, y) {
circos.text(
CELL_META$xcenter, CELL_META$ylim[1],
CELL_META$sector.index, facing = "clockwise",
niceFacing = TRUE, adj = c(0, 0.5),
cex = 0.8
)
}, bg.border = NA
)
Plot the circos plot for the all contact-dependent interactions.
abbrev = toupper(abbreviate(levels(cs@clusters), minlength = 3))
abbrev[4] = "N_1"
slot.use = "contact-Raw_smooth"
edge.df = getNormEdgeDF(cs, db.use = slot.use)
edge.mtx = DFtoMtx(edge.df)
clust.col = colors.list[c(rownames(edge.mtx), colnames(edge.mtx))]
# abbreviate the row and column names to two letters
edge.mtx.1 = edge.mtx
rownames(edge.mtx.1) = unname(abbrev[rownames(edge.mtx.1)])
colnames(edge.mtx.1) = unname(abbrev[colnames(edge.mtx.1)])
rownames(edge.mtx.1) = paste0("s-", rownames(edge.mtx.1))
colnames(edge.mtx.1) = paste0("r-", colnames(edge.mtx.1))
names(clust.col) = c(rownames(edge.mtx.1), colnames(edge.mtx.1))
# set the order based on the rowSums and colSums
col.order = colnames(edge.mtx.1)[order(colSums(edge.mtx.1), decreasing = T)]
row.order = rownames(edge.mtx.1)[order(rowSums(edge.mtx.1), decreasing = F)]
# chordDiagram takes union(rownames, colnames) as the order
use.order = c(row.order, col.order)
# plotting circos
circos.clear()
circos.par("track.height"=0.8, cell.padding=c(0, 0, 0, 0))
par(cex = 1, mar = c(0, 0, 0, 0))
chordDiagram(
edge.mtx.1, big.gap = 15, grid.col = clust.col, annotationTrack = "grid", order = use.order,
annotationTrackHeight = c(0.03, 0.01),
preAllocateTracks = list(
track.height = max(strwidth(unlist(dimnames(edge.mtx.1))))/2
)
)
circos.track(
track.index = 1, panel.fun = function(x, y) {
circos.text(
CELL_META$xcenter, CELL_META$ylim[1],
CELL_META$sector.index, facing = "clockwise",
niceFacing = TRUE, adj = c(0, 0.5),
cex = 0.8
)
}, bg.border = NA
)